package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishFlavorMapper;
import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {
    @Autowired(required = false)
    private DishFlavorMapper dishFlavorMapper;

    @Override
    public void saveWithFlavor(List<DishFlavor> flavors) {
        for (DishFlavor flavor : flavors) {
            dishFlavorMapper.insert(flavor);
        }
    }

    @Override
    public List<DishFlavor> findByDishId(Long id) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId, id);
        return dishFlavorMapper.selectList(lqw);
    }
}
